package cn.codergege.gradle.plugin

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import java.io.File

/**
 * 构建项目脚手架
 */
open class Stage: DefaultTask() {
    // 定义 main, test 目录结构
    var mainDirName = "src/main"
    var testDirName = "src/test"
    var resourcesName = "resources"

    // 定义包, 包路径
    var module = "demo" // 默认 demo
    var packageName = "cn.codergege.$module"
    var packageDir = "cn/codergege/$module"


    var mainDir = File(project.projectDir, mainDirName)
    var testDir = File(project.projectDir, testDirName)
    var mainResourceDir = File(mainDir, resourcesName)

    @TaskAction
    open fun run() {
        println("开始构建项目 ${project.name} 脚手架...")
        // 创建项目结构
        mainDir.mkdirs()
        testDir.mkdirs()
        mainResourceDir.mkdirs()
        generateFile("README.md", readmeMd)
        generateFile(".gitignore", gitignore)
        println("-------------------------")
    }

    open var readmeMd = """# ${project.name} #

## Quick Start ##

```bash
gradle test
gradle
```
## 使用的技术 ##

* Kotlin

## Todo ##

"""
    open var gitignore = """.gradle
/build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

### 前端 ###
node_modules/

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
"""
}

